package user

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/userServiceClient/userrpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserBatchAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员管理 - 批量批量添加用户
func NewUserBatchAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBatchAddLogic {
	return &UserBatchAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserBatchAddLogic) UserBatchAdd(req *types.UserBatchAddRequest) (resp *types.UserBatchAddResponse, err error) {
	rpcReq := &userrpc.UserBatchAddRequest{}
	for _, user := range req.Users {
		rpcReq.Users = append(rpcReq.Users, &userrpc.User{
			Id:             user.Id,
			Account:        user.Account,
			Phone:          user.Phone,
			Email:          user.Email,
			Password:       user.Password,
			Nickname:       user.Nickname,
			Sex:            user.Sex,
			AvatarUrl:      user.AvatarUrl,
			InviteCode:     user.InviteCode,
			ChannelCode:    user.ChannelCode,
			RegisterIp:     user.RegisterIp,
			RegisterDevice: user.RegisterDevice,
			RegisterTime:   user.RegisterTime,
			FirstLoginTime: user.FirstLoginTime,
			LastOnlineTime: user.LastOnlineTime,
			GroupId:        user.GroupId,
			IsBlacklist:    user.IsBlacklist,
			IsOnline:       user.IsOnline,
			Status:         user.Status,
			AgentLevel:     user.AgentLevel,
			VipLevel:       user.VipLevel,
			Remark:         user.Remark,
		})

	}
	_, err = l.svcCtx.UserServiceRPC.UserBatchAdd(l.ctx, rpcReq)
	if err != nil {
		return nil, err
	}
	return &types.UserBatchAddResponse{}, nil
}
